import java.util.Queue;
import java.util.Stack;

public class Offer06 {
    public class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    class Solution {
        public int[] reversePrint(ListNode head) {
            Stack<Integer> stack = new Stack<>();
            while (head != null) {
                stack.push(head.val);
                head = head.next;
            }
            int size = stack.size();
            int[] res = new int[size];
            for (int i = 0; i < size; i++) {
                res[i] = stack.pop();
            }
            return res;
        }
    }

}
